import requests
from django.test import TestCase

# Create your tests here.


# url = 'http://127.0.0.1:8000/api/module/names/1'
# res = requests.get(url=url)
# print(res.json())

dict_data = {
            "method": "GET",
            "host": "",
            "port": "",
            "url": "",
            "apiParams": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "apiParamsPublic": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "apiHeaders": [
                {
                    "keyName": "Content-Type",
                    "value": "application/json"
                },
                {
                    "keyName": "User-Agent",
                    "value": "Mozilla/5.0 LiuXiang"
                },
                {
                    "keyName": "Authorization",
                    "value": "public"
                }
            ],
            "apiHeadersPublic": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "apiBodyType": 2,
            "apiFormData": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "apiBodyPublic": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "apiBodyJson": {},
            "extract": [
                {
                    "keyName": "123",
                    "value": "321"
                }
            ],
            "validate": [
                {
                    "keyName": "123",
                    "comparator": "equals",
                    "valueType": "string",
                    "value": "132"
                }
            ]
        }

print(dict_data)


def format_to_request_param(requset_params):
    if len(requset_params) > 0:
        requset_json = {}
        print(type(requset_params))
        for i in requset_params:
            print(i['keyName'] + ': ' + i['value'])
            requset_json[i['keyName']] = i['value']
        print(requset_json)
        return requset_json
    else:
        return '无数据'
format_to_request_param(dict_data['apiHeaders'])




"""
id
接口名称
所属项目
所属模块
请求参数：
    请求方法
    域名
    端口
    路径
    路径参数
    依赖路径参数
    请求头
    依赖请求头
    请求体
    依赖请求体
    提取数据
    断言
创建时间
更新时间
"""